<link rel="stylesheet" href="/css/sweetalert/sweetalert.css"/>
<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-sm-4">
        <h2>菜单列表</h2>
        <ol class="breadcrumb">
            <li>
                <a href="{{route('/')}}">首页</a>
            </li>
            <li>
                <strong>菜单列表</strong>
            </li>
        </ol>
    </div>
    <div class="col-sm-8">
        <div class="title-action">
            <a href="{{route('newmenu')}}" class="btn btn-primary newmenu">新建菜单</a>
            <a href="javascript:void(0);" class="btn btn-warning makemenu">生成菜单</a>
        </div>
    </div>
</div>
<div class="wrapper wrapper-content animated fadeInUp">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>菜单列表<small>：）</small></h5>

                </div>
                <div class="ibox-content">
                <div class="row m-b-sm m-t-sm">
                    <div class="col-md-1">
                        <button type="button" id="loading-example-btn" class="btn btn-white btn-sm"><i class="fa fa-refresh"></i> <a href="{{route('menu.index')}}" class="fresh-loading">刷新</a></button>
                    </div>
                </div>

                <div class="project-list">

                <table class="table table-hover">
                <tbody>
                @foreach ($menuList as $menu)
                    @if ($menu->belongto == 0)
                    <tr>
                        <td class="project-status">
                            <span class="label label-danger">一级菜单</span>
                        </td>
                        <td class="project-title">
                            <a href="javascript:void(0);">{{$menu->menuname}}</a>
                            <br/>
                            <small>{{$menu->menukeyword}}</small>
                        </td>
                        <td class="project-completion">
                            <small>排序值：{{$menu->menuvalue}}</small>
                        </td>
                        <td class="project-actions">
                            <a href="{{route('menu.edit',$menu->id)}}" data-id="{{$menu->id}}"  class="btn btn-white btn-sm menu-edit"><i class="fa fa-folder"></i> 编辑 </a>
                            <a href="javascript:void(0);" data-id="{{$menu->id}}" class="btn btn-white btn-sm menu-delete delmenu"><i class="fa fa-pencil"></i> 删除 </a>
                        </td>
                    </tr>

                    @foreach ($menuList as $menu2)
                        @if ($menu2->belongto == $menu->id)
                        <tr>
                            <td class="project-status">
                                <span class="label label-primary">二级菜单</span>
                            </td>
                            <td class="project-title">
                                <a href="javascript:void(0);">{{$menu2->menuname}}</a>
                                <br/>
                                <small>{{$menu2->menukeyword}}</small>
                            </td>
                            <td class="project-completion">
                                <small>排序值：{{$menu2->menuvalue}}</small>
                            </td>
                            <td class="project-actions">
                                <a href="{{route('menu.edit',$menu2->id)}}" data-id="{{$menu2->id}}"  class="btn btn-white btn-sm menu-edit"><i class="fa fa-folder"></i> 编辑 </a>
                                <a href="javascript:void(0);" data-id="{{$menu2->id}}" class="btn btn-white btn-sm delmenu"><i class="fa fa-pencil"></i> 删除 </a>
                            </td>
                        </tr>
                        @endif
                    @endforeach

                    @endif
                @endforeach



                </tbody>
                </table>
                </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="/js/sweetalert/sweetalert.min.js"></script>
<script>
    $('.delmenu').on('click', function() {
        $menuId = $(this).data('id');
        console.log($menuId);
        swal({
                title: "不要冲动",
                text: "你确定要删除这个菜单吗？",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确定!",
                cancelButtonText: "取消",
                closeOnConfirm: false,
                showLoaderOnConfirm: true
            },
            function(){
                $.ajax({
                    url : "{{route('menu.destroy')}}",
                    type: 'DELETE',
                    data:{'menuid':$menuId},
                    success: function(data) {
                        if(data.code==2000) {
                            swal("成功!请点下刷新按钮~", data.message, "success");
                        }else {
                            swal("失败!", data.message, "error");
                        }
                    }
                });

            }
        );
    });

    $('.makemenu').on('click', function() {
        swal({
                title: "准备好了吗~",
                text: "你确定要生成整个菜单吗？",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确定!",
                cancelButtonText: "取消",
                closeOnConfirm: false,
                showLoaderOnConfirm: true
            },
            function(){
                $.ajax({
                    url : "{{route('makemenu')}}",
                    type: 'POST',
                    success: function(data) {
                        if(data.code==2000) {
                            swal("成功!~", data.message, "success");
                        }else {
                            swal("失败!", data.message, "error");
                        }
                    }
                });

            }
        );
    });
</script>